package com.trkj.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.Tbpower;
import com.trkj.service.HwcPowerService;
import com.trkj.vo.Result;

@Controller
public class HwcPowerController {
	@Autowired
	private HwcPowerService powerService;
	/**
	 * 跳转到权限分配页面
	 * @return
	 */
	@RequestMapping("/hwc_toPower")
	public String toPower(){
		return "hwc_power";
	}
	
	
	/****************************************************************/

	/**
	 * 根据传入的员工编号在组合表中查出权限对象
	 */
	@RequestMapping("/hwc_queryStaffPower")
	public @ResponseBody List<Tbpower>queryStaffNoByPowers(long staffNo){
		return powerService.queryStaffNoByPowers(staffNo);
	}
	/**
	 * 根据传入的员工编号查询不相关的权限对象
	 * @param staffNo
	 * @return
	 */
	@RequestMapping("/hwc_queryNotStaffPower")
	public @ResponseBody List<Tbpower>queryStaffNoByNotPowers(long staffNo){
		return powerService.queryStaffNoByNotPowers(staffNo);
	} 
	/**
	 * 根据传入的字符以及编号模糊查询不属于该员工的权限
	 * @param staffNo
	 * @param powerGrade
	 * @return
	 */
	@RequestMapping("/queryNotStaffNotPowers")
	public @ResponseBody List<Tbpower>queryNotStaffNotPowers(long staffNo,String powerGrade){
		return powerService.queryNotStaffNoByNotPowers(staffNo, powerGrade);
	}
	
	/**
	 * 根据传入的字符查询权限
	 * @param staffNo
	 * @param powerGrade
	 * @return
	 */
	@RequestMapping("/queryPowerGradeByPowers")
	public @ResponseBody List<Tbpower>queryPowerGradeByPowers(long staffNo,String powerGrade){
		return powerService.queryPowerNameNoByPowers(staffNo, powerGrade);
		
	}
	/**
	 * 添加员工权限
	 * @param powerNos
	 * @param staffNo
	 * @return
	 */
	@RequestMapping("/hwc_addStaffPowers")
	public @ResponseBody Result addStaffPowers(long staffNo,Long[] list){
		
		powerService.addStaffPowers(list, new BigDecimal(staffNo));
		/*for(Object l : powerNos){
			System.out.println("添加员工权限 员工编号"+staffNo+"权限编号"+l);
		}*/
		return new Result();
	}
	
	/**
	 * 移除员工的权限
	 * @param staffNo
	 * @param list
	 * @return
	 */
	@RequestMapping("/hwc_delStaffPowers")
	public @ResponseBody Result delStaffPowers(long staffNo,Long[] list){
			powerService.moveStaffPowers(list, new BigDecimal(staffNo));
			return new Result();
	}
}
